import 'dart:async';

import 'package:qgchat/bloc/blocProvider.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/apis/user.dart';
import 'package:qgchat/http/models/reflectInfoModel.dart';
import 'package:qgchat/states/states_model/index.dart';

class CashOutRecordBloc implements BlocBase {
  StreamController _cashInfo = StreamController.broadcast();
  Sink get _cashInfoSink => _cashInfo.sink;
  Stream get cashInfoStream => _cashInfo.stream;

  CashOutRecordBloc() {
    cashInfoList();
  }
  
  void dispose() {
    _cashInfo.close();
  }

  int page = 1;

  List<ReflectInfoModel> list = [];

  void cashInfoList() async {
    UserState user = state(Global.context, 'user');
    List<ReflectInfoModel> result = await UserApis.reflectInfo(user.info.memberToken, page: page);
    list.addAll(result);
    _cashInfoSink.add(result);
  }

  void onLoad() async {
    ++page;
    cashInfoList();
  }
}